package com.exam.controller;


import com.exam.entity.ApiResult;
import com.exam.entity.Teacher;
import com.exam.serviceimpl.TeacherServiceImpl;
import com.exam.util.ApiResultHandler;
import com.github.pagehelper.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
@RequestMapping(value = {"/teachercontroller"})
public class TeacherController {

    private TeacherServiceImpl teacherService;
    @Autowired
    public TeacherController(TeacherServiceImpl teacherService){
        this.teacherService = teacherService;
    }

    @RequestMapping("/findAllteachers/{page}/{size}")
    public ResponseEntity<Page<Teacher>> findAll(@PathVariable Integer page, @PathVariable Integer size){
        Page<Teacher> teacherPage = new Page<>(page,size);
        List<Teacher> teacherList=this.teacherService.findAll(page, size);

        return  new ResponseEntity<Page<Teacher>>((Page<Teacher>) teacherList, HttpStatus.OK);
    }

    @RequestMapping("/findByIdteacher/{teacherId}")
    public ResponseEntity<Teacher> findById(@PathVariable("teacherId") Integer teacherId){
        return new ResponseEntity<Teacher>(this.teacherService.findById(teacherId),HttpStatus.OK);
    }

    @RequestMapping("/teacher/{teacherId}")
    public ResponseEntity<Integer> deleteById(@PathVariable("teacherId") Integer teacherId){
        return  new ResponseEntity<Integer>(this.teacherService.deleteById(teacherId),HttpStatus.OK);
    }

    @RequestMapping("/updateteacher")
    public ResponseEntity<Integer> update(@RequestBody Teacher teacher){
        return  new ResponseEntity<Integer>(this.teacherService.update(teacher),HttpStatus.OK);
    }

    @RequestMapping("/addteacher")
    public ResponseEntity<Integer> add(@RequestBody Teacher teacher){
        return  new ResponseEntity<Integer>(this.teacherService.add(teacher),HttpStatus.OK);


    }
}
